<template>
  <div class="flow-box">
    <el-table
        :data="tableData"
        stripe
        style="width: 100%"
        border
        max-height="80vh"
        empty-text="暂无数据"
    >
      <el-table-column
          fixed
          prop="flow_index"
          label="ID"
          width="60"
          align="center"
      />
      <el-table-column
          prop="flow_uploader_name"
          label="申请人"
          width="100"
          align="center"
      />
      <el-table-column
          label="申请时间"
          width="120"
          align="center"
      >
        <template #default="{row}">
          {{computeDate(row.created_at)}}
        </template>
      </el-table-column>
      <el-table-column
          prop="type"
          label="审批类型"
          align="center"
          width="120"
      >
        <template #default="{row}">
          <el-tag v-if="row.flow_type === 0">请假</el-tag>
          <el-tag v-else-if="row.flow_type === 1">用印</el-tag>
          <el-tag v-else>报销</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="status"
          label="状态"
          align="center"
          width="120"
      >
        <template #default="{row}">
          <el-tag type="info" v-if="row.status === 0">已提交</el-tag>
          <el-tag type="warning" v-else-if="row.status === 1">审批中</el-tag>
          <el-tag type="success" v-else>已完成</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="status"
          label="当前结果"
          align="center"
          width="120"
      >
        <template #default="{row}">
          <el-tag type="warning" v-if="row.result === 0">拒绝</el-tag>
          <el-tag type="success" v-else-if="row.result === 1">通过</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="operator_name"
          label="当前/最后审批人"
          align="center"
          width="150"
      />
      <el-table-column
          prop="flow_detail"
          label="理由/说明/备注"
          width="550"
          align="center"
      />
      <el-table-column
          label="操作"
          align="center"
      >
        <template #default="{row}">
          <el-button
              type="primary"
              size="small"
              @click="showDetails(row.application_id)"
          >
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>

  <RreViewDialog ref="preRef"  @refreshRefused='getList'/>
</template>

<script setup>
import {ElTable, ElTableColumn, ElTag, ElButton, ElMessage} from "element-plus"
import {onMounted, ref} from "vue"
import {getRefuseFlowList} from "@/api"
import RreViewDialog from "@/components/Common/OA/PreViewDialog.vue"
import {useRoute, useRouter} from "vue-router"
import emitter from "@/lib/eventBus"


const route = useRoute()
const router = useRouter()

let userInfo
const tableData = ref([])
const preRef = ref()

onMounted(()=>{
  emitter.emit('home_menu','/OA/my-leave/list')
  emitter.emit('updateMyLeave','/OA/my-leave/refuse')
  if (route.path !== '/OA/my-leave/refuse') router.push('/OA/my-leave/refuse')
  getinfo()
  getList()
})

const getinfo = () => {
  userInfo = JSON.parse(localStorage.getItem('syhyDocManSys'))
}

const getList = async () => {
  try {
    const {data:res} = await getRefuseFlowList({
      userId:userInfo.id
    })
    if(res.code === 200){
      tableData.value = res.data
    } else if (res.code === 201){
      // return ElMessage({
      //   message:'未查询到被拒绝的流程',
      //   type:'info'
      // })
    } else {
      return ElMessage({
        message:'未查询到被拒绝的流程',
        type:'info'
      })
    }
  } catch (e) {
    console.log(e)
  }
}

const showDetails = (id) => {
  preRef.value.showDetails(id)
}

const computeDate = (date) => {
  return date.substring(0,10)
}

</script>

<style scoped lang="less">
:deep(.el-dialog__body ){
  padding: 0 !important;
}
</style>
